﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace DEMO_TEMP1
{

    public partial class Confirm : UserControl
    {
        WebPor.Service1 ls = new WebPor.Service1();
        DataSet ds = new DataSet();
        string m, l, p, bal, mawbNodet = string.Empty;
        string storepcs, userid, location, slipid = string.Empty;
        int index = 0;
        public Confirm(string user, DataSet data, string storepcs, string locate, int index)
        {
            InitializeComponent();
            this.ds = data;
            this.storepcs = storepcs;
            this.location = locate;
            this.index = index;
            this.userid = user;
            if (ds == null)
            {
                MessageBox.Show("Data Not Found");
            }
            else
            {
                m = ds.Tables[0].Rows[index]["display_mawb"].ToString(); //mawb;
                l = locate;

                p = storepcs;

                Setdata(m, l, storepcs);
            }



        }

        private void Setdata(string m, string l, string p)
        {
            label6.Text = m;
            label7.Text = l;
            label8.Text = p;
            mawbNodet = ds.Tables[0].Rows[index]["mawb_prefix"].ToString() + ds.Tables[0].Rows[index]["mawb_sn"].ToString();
            slipid = ds.Tables[0].Rows[index]["slip_id"].ToString();

        }

        private void button1_Click(object sender, EventArgs e)
        {


            // int store= Convert.ToInt32(storepcs);
            int total = Convert.ToInt32(ds.Tables[0].Rows[index]["total_piece_count"]);
            int store = Convert.ToInt32(ds.Tables[0].Rows[index]["stored_piece_count"]);
            int bal = total - store;
            int sto = Convert.ToInt32(storepcs);
            if (bal - sto == 0)
            {
                CallStoUpdate2(userid, l, mawbNodet, p, slipid);


            }
            else
            {
                CallStoUpdate(userid, l, mawbNodet, p, slipid);

            }

        }

        private void CallStoUpdate2(string userid, string l, string mawbNodet, string p, string slipid)
        {
            string status, mes = string.Empty;

            ls.Url = String.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            usp_HHTStoreCargo = ls.usp_HHTStoreCargo(userid, l, mawbNodet, p, slipid);
            status = usp_HHTStoreCargo.Tables[0].Rows[0]["vchStatus"].ToString();
            mes = usp_HHTStoreCargo.Tables[0].Rows[0]["vchMessage"].ToString();
            if (status == "PASS")
            {

                ScanMAWB SM = new ScanMAWB(userid);
                SM.Show();

            }
            else
            {
                MessageBox.Show(mes);
            }
        }
        DataSet usp_HHTStoreCargo = new DataSet();
        private void CallStoUpdate(string userid, string l, string mawbNodet, string p, string slipid)
        {
            string status, mes = string.Empty;

            ls.Url = String.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            usp_HHTStoreCargo = ls.usp_HHTStoreCargo(userid, l, mawbNodet, p, slipid);
            status = usp_HHTStoreCargo.Tables[0].Rows[0]["vchStatus"].ToString();
            mes = usp_HHTStoreCargo.Tables[0].Rows[0]["vchMessage"].ToString();
            if (status == "PASS")
            {
                //ds = ls.Getdata(m);
                Scanlocation sl = new Scanlocation(userid, m, index);
                sl.Show();

            }
            else
            {
                MessageBox.Show(mes);
            }
            //MessageBox.Show(status);

        }

        private void Confirm_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Scanlocation lc = new Scanlocation(userid, m, index);
            lc.textBox3.Text = "";
            lc.textBox2.Text = l;
            lc.textBox3.Focus();
            lc.Show();
            //this.Dispose();
        }

    }


}
